package com.fosun.spr.core.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fosun.spr.core.utils.CookieUtil;

public class PermissionInterceptor {

	public static final String LOGIN_IDENTITY_KEY = "LOGIN_IDENTITY";
	public static final String LOGIN_IDENTITY_VAL = "sdf!121sdf$78sd!8";

	public static boolean login(HttpServletResponse response, boolean ifRemember) {
		CookieUtil.set(response, LOGIN_IDENTITY_KEY, LOGIN_IDENTITY_VAL,
				ifRemember);
		return true;
	}

	public static void logout(HttpServletRequest request,
			HttpServletResponse response) {
		CookieUtil.remove(request, response, LOGIN_IDENTITY_KEY);
	}

	public static boolean ifLogin(HttpServletRequest request) {
		String indentityInfo = CookieUtil.getValue(request, LOGIN_IDENTITY_KEY);
		if (indentityInfo == null
				|| !LOGIN_IDENTITY_VAL.equals(indentityInfo.trim())) {
			return false;
		}
		return true;
	}
}
